<?php

/**
 *   OPENSHOP 管理中心taobao 用户管理API
 * 
 *   @link        http://baison.com.cn
 *   @copyright   Baison, Inc.
 *   @package     OpenShop
 *   @version     $Id: api_tb_user.php,v 1.0 2009年10月17日13:30:13 created$
 *   @author      winner <jsycywm@hotmail.com>
 */

define('IN_OS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . '/includes/modules/taobao.api/cls_api.php');
  
	
	 
if ($_REQUEST['act'] == 'list'){	
	//检查权限
	admin_priv(); //API用户参数 
		$userParamArr = array( 
					'parent_cid'=>'0' 
	     		);    
        $result = Top_ItemcatsGet( $userParamArr ); 
        if(is_array($result) && is_array( $result['item_cat']  ) ){
        		$arr = array();
				foreach ($result['item_cat'] as $row ){  
				    $row['tb_itemcat_id'] = Check_is_exist( 'tb_itemcat','cid',$row['cid'] ) ;//存在表示已经下载 
				    $arr[] = $row;
				}
				if(!is_array($arr[0])) {
					 $subresult[0] = $result['item_cat'];
				} else {
					$subresult = $arr;
				}  	
        } 
		$result['item_cat'] = $subresult ;   
		$smarty->assign('stuats', 'list' );  
 		$smarty->assign('item_cat', $result );  
	    $smarty->assign('ur_here', 'taobao类目下载');
	    assign_query_info(); 
        $smarty->display('api_tb_itemcat_manage.tpl');
}elseif($_REQUEST['act'] == 'sellercatlist'){  
	    if( Check_is_exist("tb_sellercat", 'nick', API_USER) ) GetShopSellercats();//taobao.sellercats.list.get(获取前台展示的店铺内卖家自定义商品类目)
 		$sql="select * from open_tb_sellercat where nick='".API_USER."'";  
        $result['item_cat'] = $db->getAll($sql);
		$smarty->assign('stuats', 'sellercatlist' );  
 		$smarty->assign('item_cat', $result );  
	    $smarty->assign('ur_here', '买家自定义类目');
	    assign_query_info(); 
        $smarty->display('api_tb_itemcat_manage.tpl');
}elseif($_REQUEST['act'] == 'downlist'){  
		$sql="select * from open_tb_itemcat"; 
        $result['item_cat'] = $db->getAll($sql);
		$smarty->assign('stuats', 'downlist' );  
 		$smarty->assign('item_cat', $result );  
	    $smarty->assign('ur_here', '买家自定义类目');
	    assign_query_info(); 
        $smarty->display('api_tb_itemcat_manage.tpl');
}elseif($_REQUEST['act'] == 'get_item'){  
 		$cid=$_REQUEST['cid'];  
		$name=$_REQUEST['name'];  
		AddItemCat( $cid );  //先下载类目  
	    echo ('类目下载成功! <a href="#" onclick="history.go(-1)">返回</a>');
}elseif($_REQUEST['act'] == 'authorize'){    //(查询B商家被授权品牌列表和类目列表)   
		//API用户参数
	 	$userParamArr = array( 
							'fields'=>'brand.vid, brand.name,item_cat.cid,item_cat.name,item_cat.status,item_cat.sort_order,item_cat.parent_cid,item_cat.is_parent'
					 	);    
	    $result = Top_ItemcatsAuthorizeGet( $userParamArr ); //taobao.itemcats.authorize.get :查询B商家被授权品牌列表和类目列表   [商]   
 	    if($result[code]) die('下载出错:['.$result[code].']'. $result['msg']); 
	    if(is_array($brand= $result['authorize']['brands']['brand']))  $brand['nick'] =  $_CFG['taobao_user'] ;  
	    OS_InsertIntoTB('tb_brand','vid', $brand );//插入品牌   
	    foreach ( $result['authorize']['item_cats']['item_cat'] as $item_cat){
		    	OS_InsertIntoTB('tb_itemcat','cid',$item_cat); 
				AddItemCat(  $item_cat['cid'] );  //先下载类目属性   
	     }    
        echo ('商家基本类目属性下载完成! <a href="#" onclick="history.go(-1)">返回</a>');
}elseif($_REQUEST['act'] == 'shop'){    //店铺基本信息下载 
	   GetPostAges();
       GetShop();
       GetShopCats();
       GetShopSellercats();//taobao.sellercats.list.get(获取前台展示的店铺内卖家自定义商品类目)
	   echo ('下载成功! <a href="#" onclick="history.go(-1)">返回</a>'); 
}

?>